{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Python Algorithmic Trading Cookbook"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Chapter 7: Placing Bracket and Cover Orders on the Exchange"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This Jupyter Notebook is created using Python version 3.8.2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Requirements"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can install the requirements for this Jupyter Notebook by executing the below cell"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install pyalgotrading"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Master Recipe\n",
    "\n",
    "The following code will help you set up the broker connection with Zerodha, which will be used by all the recipes in this chapter. Please make sure you have followed these steps before trying out any recipe. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyalgotrading.broker.broker_connection_zerodha import BrokerConnectionZerodha\n",
    "from pyalgotrading.constants import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Installing package kiteconnect via pip. This may take a while...\n",
      "Please login to this link to generate your request token: https://kite.trade/connect/login?api_key=<your-api-key>&v=3\n"
     ]
    }
   ],
   "source": [
    "# Get the api_key and api_secret from broker. These are unique to you and will be used by the broker to identify your demat account.\n",
    "api_key = \"<your-api-key>\"\n",
    "api_secret = \"<your-api-secret>\"\n",
    "broker_connection = BrokerConnectionZerodha(api_key, api_secret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get the request token from the above URL\n",
    "request_token = \"<your-request-token>\"\n",
    "broker_connection.set_access_token(request_token)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipe 1: Placing a Bracket Limit Order"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "instrument = broker_connection.get_instrument('NSE', 'SBIN')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2003030003491923'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Place a Buy, Bracket, Intraday, Limit order\n",
    "ltp = broker_connection.get_ltp(instrument)\n",
    "\n",
    "order1_id = broker_connection.place_order(instrument=instrument,\n",
    "    order_transaction_type=BrokerOrderTransactionTypeConstants.BUY,\n",
    "    order_type=BrokerOrderTypeConstants.BRACKET,\n",
    "    order_code=BrokerOrderCodeConstants.INTRADAY,\n",
    "    order_variety=BrokerOrderVarietyConstants.LIMIT,\n",
    "    quantity=1,\n",
    "    price=ltp-1,\n",
    "    stoploss=2,\n",
    "    target=2)\n",
    "\n",
    "order1_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'OPEN'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order1_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'COMPLETE'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order1_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'200303003639902'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Place a Sell, Bracket, Intraday, Limit order\n",
    "ltp = broker_connection.get_ltp(instrument)\n",
    "\n",
    "order2_id = broker_connection.place_order(instrument=instrument,\n",
    "    order_transaction_type=BrokerOrderTransactionTypeConstants.SELL,\n",
    "    order_type=BrokerOrderTypeConstants.BRACKET,\n",
    "    order_code=BrokerOrderCodeConstants.INTRADAY,\n",
    "    order_variety=BrokerOrderVarietyConstants.LIMIT,\n",
    "    quantity=1,\n",
    "    price=ltp+1,\n",
    "    stoploss=2,\n",
    "    target=2)\n",
    "\n",
    "order2_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'OPEN'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order2_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'COMPLETE'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order2_id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipe 2: Placing a Bracket Stoploss-Limit Order"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "instrument = broker_connection.get_instrument('NSE', 'INDUSINDBK')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'200226003619998'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Place a Buy, Bracket, Intraday, Stoploss Limit order\n",
    "ltp = broker_connection.get_ltp(instrument)\n",
    "\n",
    "order1_id = broker_connection.place_order(instrument=instrument,\n",
    "    order_transaction_type=BrokerOrderTransactionTypeConstants.BUY,\n",
    "    order_type=BrokerOrderTypeConstants.BRACKET,\n",
    "    order_code=BrokerOrderCodeConstants.INTRADAY,\n",
    "    order_variety=BrokerOrderVarietyConstants.STOPLOSS_LIMIT,\n",
    "    quantity=1,\n",
    "    price=ltp+1,\n",
    "    trigger_price=ltp+1,\n",
    "    stoploss=2,\n",
    "    target=2)\n",
    "\n",
    "order1_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'TRIGGER PENDING'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order1_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'COMPLETE'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order1_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'200226003620002'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Place a Sell, Bracket, Intraday, Stoploss Limit order\n",
    "ltp = broker_connection.get_ltp(instrument)\n",
    "\n",
    "order2_id = broker_connection.place_order(instrument=instrument,\n",
    "    order_transaction_type=BrokerOrderTransactionTypeConstants.SELL,\n",
    "    order_type=BrokerOrderTypeConstants.BRACKET,\n",
    "    order_code=BrokerOrderCodeConstants.INTRADAY,\n",
    "    order_variety=BrokerOrderVarietyConstants.STOPLOSS_LIMIT,\n",
    "    quantity=1,\n",
    "    price=ltp-1,\n",
    "    trigger_price=ltp-1,\n",
    "    stoploss=2,\n",
    "    target=2)\n",
    "\n",
    "order2_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'TRIGGER PENDING'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order2_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'COMPLETE'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order2_id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipe 3: Placing a Bracket Limit Order with Trailing Stoploss"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "instrument = broker_connection.get_instrument('NSE', 'FEDERALBNK')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'200226003620004'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Place a Buy, Bracket, Intraday, Limit order\n",
    "ltp = broker_connection.get_ltp(instrument)\n",
    "\n",
    "order1_id = broker_connection.place_order(instrument=instrument,\n",
    "    order_transaction_type=BrokerOrderTransactionTypeConstants.BUY,\n",
    "    order_type=BrokerOrderTypeConstants.BRACKET,\n",
    "    order_code=BrokerOrderCodeConstants.INTRADAY,\n",
    "    order_variety=BrokerOrderVarietyConstants.LIMIT,\n",
    "    quantity=1,\n",
    "    price=ltp-1,\n",
    "    trigger_price=ltp-1,\n",
    "    stoploss=2,\n",
    "    target=2,\n",
    "    trailing_stoploss=1)\n",
    "\n",
    "order1_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'OPEN'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order1_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'COMPLETE'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order1_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'200226003620009'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Place a Sell, Bracket, Intraday, Limit order\n",
    "ltp = broker_connection.get_ltp(instrument)\n",
    "\n",
    "order2_id = broker_connection.place_order(instrument=instrument,\n",
    "    order_transaction_type=BrokerOrderTransactionTypeConstants.SELL,\n",
    "    order_type=BrokerOrderTypeConstants.BRACKET,\n",
    "    order_code=BrokerOrderCodeConstants.INTRADAY,\n",
    "    order_variety=BrokerOrderVarietyConstants.LIMIT,\n",
    "    quantity=1,\n",
    "    price=ltp+1,\n",
    "    trigger_price=ltp+1,\n",
    "    stoploss=2,\n",
    "    target=2,\n",
    "    trailing_stoploss=1)\n",
    "\n",
    "order1_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'OPEN'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order2_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'COMPLETE'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order2_id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipe 4: Placing a Bracket Stoploss-Limit Order with Trailing Stoploss"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "instrument = broker_connection.get_instrument('NSE', 'RBLBANK')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'200226003620011'"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Place a Buy, Bracket, Intraday, Limit order\n",
    "ltp = broker_connection.get_ltp(instrument)\n",
    "\n",
    "order1_id = broker_connection.place_order(instrument=instrument,\n",
    "    order_transaction_type=BrokerOrderTransactionTypeConstants.BUY,\n",
    "    order_type=BrokerOrderTypeConstants.BRACKET,\n",
    "    order_code=BrokerOrderCodeConstants.INTRADAY,\n",
    "    order_variety=BrokerOrderVarietyConstants.STOPLOSS_LIMIT,\n",
    "    quantity=1,\n",
    "    price=ltp+1,\n",
    "    trigger_price=ltp+1,\n",
    "    stoploss=2,\n",
    "    target=2,\n",
    "    trailing_stoploss=1)\n",
    "\n",
    "order1_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'TRIGGER PENDING'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order1_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'COMPLETE'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order1_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'200226003620023'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Place a Sell, Bracket, Intraday, Limit order\n",
    "ltp = broker_connection.get_ltp(instrument)\n",
    "\n",
    "order2_id = broker_connection.place_order(instrument=instrument,\n",
    "    order_transaction_type=BrokerOrderTransactionTypeConstants.SELL,\n",
    "    order_type=BrokerOrderTypeConstants.BRACKET,\n",
    "    order_code=BrokerOrderCodeConstants.INTRADAY,\n",
    "    order_variety=BrokerOrderVarietyConstants.STOPLOSS_LIMIT,\n",
    "    quantity=1,\n",
    "    price=ltp-1,\n",
    "    trigger_price=ltp-1,\n",
    "    stoploss=2,\n",
    "    target=2,\n",
    "    trailing_stoploss=1)\n",
    "\n",
    "order2_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'TRIGGER PENDING'"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order2_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'COMPLETE'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order2_id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipe 5: Placing a Cover Market Order"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "instrument = broker_connection.get_instrument('NSE', 'BANKBARODA')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'200303003717532'"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Place a Buy, Cover, Intraday, Market order\n",
    "ltp = broker_connection.get_ltp(instrument)\n",
    "\n",
    "order1_id = broker_connection.place_order(instrument=instrument,\n",
    "    order_transaction_type=BrokerOrderTransactionTypeConstants.BUY,\n",
    "    order_type=BrokerOrderTypeConstants.COVER,\n",
    "    order_code=BrokerOrderCodeConstants.INTRADAY,\n",
    "    order_variety=BrokerOrderVarietyConstants.MARKET,\n",
    "    quantity=1,\n",
    "    trigger_price=ltp-1)\n",
    "\n",
    "order1_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'COMPLETE'"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order1_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'200303003732941'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Place a Sell, Cover, Intraday, Market order\n",
    "ltp = broker_connection.get_ltp(instrument)\n",
    "\n",
    "order2_id = broker_connection.place_order(instrument=instrument,\n",
    "    order_transaction_type=BrokerOrderTransactionTypeConstants.SELL,\n",
    "    order_type=BrokerOrderTypeConstants.COVER,\n",
    "    order_code=BrokerOrderCodeConstants.INTRADAY,\n",
    "    order_variety=BrokerOrderVarietyConstants.MARKET,\n",
    "    quantity=1,\n",
    "    trigger_price=ltp+1)\n",
    "\n",
    "order2_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'COMPLETE'"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order2_id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Recipe 6: Placing a Cover Limit Order"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "instrument = broker_connection.get_instrument('NSE', 'YESBANK')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'200303003749622’"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Place a Buy, Cover, Intraday, Limit order\n",
    "ltp = broker_connection.get_ltp(instrument)\n",
    "\n",
    "order1_id = broker_connection.place_order(instrument=instrument,\n",
    "    order_transaction_type=BrokerOrderTransactionTypeConstants.BUY,\n",
    "    order_type=BrokerOrderTypeConstants.COVER,\n",
    "    order_code=BrokerOrderCodeConstants.INTRADAY,\n",
    "    order_variety=BrokerOrderVarietyConstants.LIMIT,\n",
    "    quantity=1,\n",
    "    price=ltp-0.5,\n",
    "    trigger_price=ltp-1)\n",
    "\n",
    "order1_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'OPEN'"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order1_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'COMPLETE'"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order1_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'200303003751757'"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Place a Sell, Cover, Intraday, Limit order\n",
    "ltp = broker_connection.get_ltp(instrument)\n",
    "\n",
    "order2_id = broker_connection.place_order(instrument=instrument,\n",
    "    order_transaction_type=BrokerOrderTransactionTypeConstants.SELL,\n",
    "    order_type=BrokerOrderTypeConstants.COVER,\n",
    "    order_code=BrokerOrderCodeConstants.INTRADAY,\n",
    "    order_variety=BrokerOrderVarietyConstants.LIMIT,\n",
    "    quantity=1,\n",
    "    price=ltp+0.5,\n",
    "    trigger_price=ltp+1)\n",
    "\n",
    "order2_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'OPEN'"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order2_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'COMPLETE'"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "broker_connection.get_order_status(order2_id)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
